package ar.edu.utn.frgp.Banco.actions;


import java.util.Date;
import ar.edu.utn.frgp.Banco.model.PagoServicios;
import ar.edu.utn.frgp.Banco.service.BusinessException;
import ar.edu.utn.frgp.Banco.service.IRecursoService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

	public class PagoServicioAction extends ActionSupport implements ModelDriven<PagoServicios> {
		

		private static final long serialVersionUID = 1L;

		private String msj;

		private PagoServicios pagoservicio = new PagoServicios();
		@Autowired
		private IRecursoService recursoService;

		@Override
		public String execute() {
			
			
			try {
				java.util.Date utilDate = new java.util.Date();
				Date sqlDate = new Date(utilDate.getTime());
				pagoservicio.setFecha(sqlDate);
				if (pagoservicio.getNrocuenta()  == 0) {
					setMsj("nro cuenta invalido");
					return ERROR;
				}
			recursoService.crearPagoServico(pagoservicio);
					
			} catch (BusinessException ex) { 
				setMsj(ex.getMessage());
			} catch (Exception e) {
				e.printStackTrace();
				return ERROR;
			}
			return SUCCESS;
		}

		public PagoServicios getModel() {
			return pagoservicio;
		}

		public String getMsj() {
			return msj;
		}

		public void setMsj(String msj) {
			this.msj = msj;
		}

	}
